package com.example.exercise.es.doctor.controller;

import com.example.exercise.es.common.BaseResponse;
import com.example.exercise.es.doctor.service.DoctorService;
import jakarta.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/")
public class DoctorController {

    @Resource
    private DoctorService doctorService;

    @RequestMapping(value = "/drop", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<Object> drop() {
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        doctorService.drop();
        baseResponse.ok();
        return baseResponse;
    }

    @RequestMapping(value = "/saveDoctor", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<Object> saveDoctor() {
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        doctorService.saveDoctor();
        baseResponse.ok();
        return baseResponse;
    }

    @RequestMapping(value = "/findByDoctorId", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<Object> findByDoctorId(Long doctorId) {
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        baseResponse.ok(doctorService.findByDoctorId(doctorId));
        return baseResponse;
    }

    @RequestMapping(value = "/findByHospitalId", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<Object> findByHospitalId(Long hospital) {
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        baseResponse.ok(doctorService.findByHospitalId(hospital));
        return baseResponse;
    }

    @RequestMapping(value = "/findByHospitalNameOrDoctorName", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<Object> findByHospitalNameOrDoctorName(String context) {
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        baseResponse.ok(doctorService.findByHospitalNameOrDoctorName(context));
        return baseResponse;
    }

    @RequestMapping(value = "/searchDoctor", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<Object> searchDoctor(String searchContent) {
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        baseResponse.ok(doctorService.searchDoctor(0,20,searchContent));
        return baseResponse;
    }

}
